home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: 101513.2141@compuserve.com (Jean-Marc Delforge)
- Newsgroups: comp.unix.programmer,comp.lang.c
- Subject: Re: Applying file masks in UNIX using C/C++
- Date: Fri, 05 Apr 1996 09:33:54 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4k2lub$9oe@dub-news-svc-1.compuserve.com>
- References: <31618AFE.5476@netrover.com>
- NNTP-Posting-Host: hd42-154.compuserve.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Stephane Charette <charrick@netrover.com> wrote:
-
- >This is a long shot...but...does anyone know of the existence
- >of public domain C/C++ code which will apply a file mask to
- >an existing filename and return a TRUE or FALSE response?
-
- >For example: if I have a mask of "a??01.text.*" and I have
- >the files "abc01.text.old", "az01.text.new" and "az01.text",
- >then it would return positive on the first two, but negative
- >on the last. Does this make sense?
-
- >What I hope, is that someone has already done all of this and
- >put it up there on an FTP site. Thing is, I can't find it...
- >WWW searches have turned up nothing so far either. (The fact
- >that I have no idea what this would be called doesn't help.)
-
- >Thanks for your help,
-
- >Stephane Charette
-
- Try This.
- This is working like UNIX wildcards.
- More best than DOS wildcards.
- It's comminig from my mind.
- It's working recusrively, and for strings of any size.
-
- /*
- ** str_filter.c
- ** (c) smals 1992
- ** Delforge jm 2641
- */
-
- #include <dos.h>
-
- int StrFilter (char * str, char * mask)
- {
- char * pm, *ps;
-
- pm = mask;
- ps = str;
-
- if (*pm == 0) return (1);
-
- while (*pm != 0)
- {
- switch (*pm)
- {
- case '*' :
- pm++;
- if (*ps == 0) return (1);
- while (*ps != 0)
- {
- if (StrFilter (ps, pm)) return (1);
- ps++;
- }
- return (0);
- case '?' :
- if (*ps == 0) return (0);
- ps++; pm++;
- break;
- default :
- if (*pm != *ps) return (0);
- pm++, ps++;
- break;
- }
- }
- if (*ps == 0) return (1);
- else return (0);
- }
-
- /* eof */
-
- Jean-Marc Delforge
- Smals - Belgium - Brussels
- 101513.2141@compuserve.com
-
-